
###########################################################################
#                            TextMate Snippets                            #
###########################################################################
snippet def "#ifndef … #define … #endif"
#ifndef ${1/([A-Za-z0-9_]+).*/$1/}
#define ${1:SYMBOL} ${2:value}
#endif
endsnippet

snippet inc "#include "" (inc)"
#include "${1:`!p res=fn.split('.')[-2]+'.h'`}"
endsnippet

snippet Inc "#include <> (Inc)"
#include <${1:.h}>
endsnippet

snippet mark "#pragma mark (mark)"
#if 0
${1:#pragma mark -
}#pragma mark $2
#endif

$0
endsnippet

snippet main "main() (main)"
int main (int argc, char const *argv[])
{
	${0:/* code */}
	return 0;
}
endsnippet

snippet for "for int loop (fori)"
for(size_t ${2:i} = 0; $2 < ${1:count}; ${3:++$2})
{
	${0:/* code */}
}
endsnippet

snippet enum "Enumeration"
enum ${1:name} { $0 };
endsnippet

snippet once "Include header once only guard"
#ifndef ${1:`!p
if not len(cur):
	import random, string
	name = re.sub(r'[^A-Za-z0-9]+','_', fn).upper()
	rand = ''.join(random.sample(string.ascii_letters+string.digits, 8))
	res = ('%s_%s' % (name,rand)).upper()`}
#define $1

${0}

#endif /* end of include guard: $1 */

endsnippet

snippet td "Typedef"
typedef ${1:int} ${2:MyCustomType};
endsnippet

snippet do "do...while loop (do)"
do {
	${0:/* code */}
} while(${1:/* condition */});
endsnippet

snippet fprintf "fprintf …"
fprintf(${1:stderr}, "${2:%s}\n"${2/([^%]|%%)*(%.)?.*/(?2:, :\);)/}$3${2/([^%]|%%)*(%.)?.*/(?2:\);)/}
endsnippet

snippet if "if .. (if)"
if(${1:/* condition */})
{
	${0:/* code */}
}
endsnippet

snippet printf "printf .. (printf)"
printf("${1:%s}\n"${1/([^%]|%%)*(%.)?.*/(?2:, :\);)/}$2${1/([^%]|%%)*(%.)?.*/(?2:\);)/}
endsnippet

snippet st "struct"
struct ${1:`!p if fn != "": res = fn.split(".")[-2].lower()+"_t"
else: res = "name"`}
{
	${0:/* data */}
};
endsnippet

